package com.czu.cy.entities;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.NonVisual;

@Entity
@NamedQueries({ @NamedQuery(name = Order.BY_USERNAME, query = "Select o from Order o where o.user.username = :username") })
@Table(name = "orders")
public class Order {

    public static final String BY_USERNAME = "Order.byUsername";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NonVisual
    @Property
    private Long id;

    @NotNull
    @ManyToOne
    @NonVisual
    @Property
    private User user;

    @Property
    @Column(nullable = false)
    private String goods;

    @Property
    @Column(nullable = false)
    private String fromAddress;

    @Property
    @Column(nullable = false)
    private String toAddress;

    @Property
    @Column(nullable = false)
    private Date creationDate;

    public Order() {
    }

    public Order(final User user) {
        this.user = user;
    }

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    public String getGoods() {
        return goods;
    }
    public void setGoods(String goods) {
        this.goods = goods;
    }
    public String getFromAddress() {
        return fromAddress;
    }
    public void setFromAddress(String fromAddress) {
        this.fromAddress = fromAddress;
    }
    public String getToAddress() {
        return toAddress;
    }
    public void setToAddress(String toAddress) {
        this.toAddress = toAddress;
    }
    public Date getCreationDate() {
        return creationDate;
    }
    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

}
